package dao.version2;

import utils.version1.ConnectionUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserInfoHistoryDao {

    private   Connection connection;

    public UserInfoHistoryDao(Connection connection) {
        this.connection = connection;
    }

    public  void insert(String userid, String username) {
        String sql = "INSERT INTO userinfohistory(userid, username) VALUES (?,?)";
       //throwError();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,userid);
            preparedStatement.setString(2,username);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException e) {
            throw new RuntimeException("error in userInfoHisitorydao");
        }
    }
    private void throwError(){
        throw new RuntimeException("模拟出错 userinfohistorydao");
    }
}
